import { createApp } from 'vue'
import App from './App.vue'
import route from './router'
import ElementPlus from 'element-plus'
import moment from 'moment'
import 'element-plus/lib/theme-chalk/index.css'
import request from './utils/request'
import storage from './utils/storage'
import api from './api'
import store from './store'
const app = createApp(App)
// 本地化，中文时间显示
moment.locale('zh-cn')

// console.log('环境变量=>', import.meta.env)
// 自定义判断按钮权限指令
app.directive('has', {
  beforeMount: (el, binding) => {
    let action = storage.getItem('userAction')
    let preaction = binding.value
    let haspreaction = action.includes(preaction)
    if (!haspreaction) {
      el.style.display = 'none'
      setTimeout(() => el.parentNode.removeChild(el))
    }
  },
})
// 挂载全局
app.config.globalProperties.$request = request
app.config.globalProperties.$storage = storage
app.config.globalProperties.$api = api
app.config.globalProperties.$moment = moment
;(async () => {
  const router = await route()
  app
    .use(router)
    .use(store)
    .use(ElementPlus, { size: 'small' })
    .mount('#app')
})()
